package com.samsung.spen.sshare.main.image;

import java.io.File;

import android.content.Context;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.util.LruCache;

public class ImageCache {
	private static final String TAG = "ImageCache";
	
	// Default memory cache size in kilobytes
	private static final int DEFAULT_MEM_CACHE_SIZE = 1024 * 5; // 5MB
	
	//Compression settings when writing images to disk cache
	
	//Constants to easily toggle various caches
	private static final boolean DEFAULT_MEM_CACHE_ENABLED = true;
	
	private LruCache<String, BitmapDrawable> mMemoryCache;
	private ImageCacheParams mCacheParams;
	
	public static class ImageCacheParams {
		public int memCacheSize = DEFAULT_MEM_CACHE_SIZE;
        public boolean memoryCacheEnabled = DEFAULT_MEM_CACHE_ENABLED;
        
        public void setMemCacheSizePercent(float percent){
        	if(percent < 0.05f || percent > 0.8f){
        		throw new IllegalArgumentException("setMemCacheSizePercent - percent must be "
                        + "between 0.05 and 0.8 (inclusive)");
        	}
        	memCacheSize = Math.round(percent*Runtime.getRuntime().maxMemory());
        }
	}
	
	private ImageCache(ImageCacheParams cacheParams){
		init(cacheParams);
	}

	private void init(ImageCacheParams cacheParams) {
		mCacheParams = cacheParams;
		
		if(mCacheParams.memoryCacheEnabled){
			mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize){
				@Override
				protected void entryRemoved(boolean evicted, String key,
						BitmapDrawable oldValue, BitmapDrawable newValue) {
				}
			};
		}
	}
}
